﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DawnOfConquest.Abilities
{
    class Attack : DawnOfConquest.Ability
    {
        
        Attack()
        {
            range = 1;
            targetType = "Enemy";
        }

        public void execute(Piece user, Piece target)
        {
            Random r = new Random();
            if (target.getName().Equals("Pikeman") && !user.getName().Equals("Pikeman"))
            {
                int chanceToHit = 99 - 2 * (user.getDefense() - target.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    user.applyDamage(target.getDamage());
                }

                chanceToHit = 99 - 2 * (target.getDefense() - user.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    target.applyDamage(user.getDamage());
                }
            }
            else
            {
                int chanceToHit = 99 - 2 * (target.getDefense() - user.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    target.applyDamage(user.getDamage());
                }

                chanceToHit = 99 - 2 * (user.getDefense() - target.getAttack());

                if (r.Next(100) < chanceToHit)
                {
                    user.applyDamage(target.getDamage());
                }
            }
        }
    }
}
